<?php

include("lib/template.inc");
include("lib/lib_dps.php");
include("nav_data.php");
$m=0;

//$developer=true;

if($dps_link!=false AND $user_now=get_current_user_obj())
{
	$dps=new dps_action($dps_username,$dps_password);//the normal user has a full privilege
	echo("saving...");
	$select_format='SELECT cfm_ID,password FROM confirm WHERE epsn="%s" AND user_ID=%d';
	$query=sprintf($select_format,$user_now->epsn,$user_now->user_ID);
	if($developer)
		echo("dps_upload.php:".$query."<br />");//to find out the infomation for this username at ccr server
	$res_cfm=mysql_query($query,$dps_link);
	if($obj_password=mysql_fetch_object($res_cfm))
	{
		if($dps->user_upload($user_now->epsn,$user_now->user_ID,$obj_password->password))
		{
			$doc[$m]["title"]="保存成功";
			$doc[$m]["content"]="您的信息已经成功的上传到了CCR上";
			$doc[$m]["wid"]="100%";
			$m++;
		}
		else
		{
			$doc[$m]["title"]="保存失败";
			$doc[$m]["content"]="对不起，您上次输入的密码不正确。请您到<a href=confirm.php>保存到CCR</a>页面重新输入密码。";
			$doc[$m]["wid"]="100%";
			$m++;
		}
		$delete_format="DELETE FROM confirm WHERE cfm_ID=%d";
		$query=sprintf($delete_format,$obj_password->cfm_ID);
		if($developer)
			echo("dps_upload.php:".$query."<br />");
		$res_nouse=mysql_query($query,$dps_link);
	}
	else
	{
		$doc[$m]["title"]="保存失败";
		$doc[$m]["content"]="对不起，您尚未确认上传。请您先到<a href=confirm.php>保存到CCR</a>页面确认上传。";
		$doc[$m]["wid"]="100%";
		$m++;
	}
}
else
{
	$doc[$m]["title"]="保存失败";
	$doc[$m]["content"]="对不起，您尚未登录。请您先<a href=confirm.php>登录DistRema平台</a>";
	$doc[$m]["wid"]="100%";
	$m++;
}

include("render.php");
render("立刻上传",$nav_title,$nav_link,$doc);
?>